﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using MDIApplication.Classes;

namespace MDIApplication
{
    public partial class DeleteAcct : Form
    {
        public DeleteAcct()
        {
            InitializeComponent();
        }

        #region DatasetBinding
        private void DeleteAcct_Load(object sender, EventArgs e)
        {
            // TODO: This line of code loads data into the 'staffByAccountIdDataSet.Staff' table. You can move, or remove it, as needed.
            this.staffTableAdapter.Fill(this.staffByAccountIdDataSet.Staff);

        }
      
        private void fillByToolStripButton_Click(object sender, EventArgs e)
        {
           

        }
        #endregion DatasetBinding

        private void btnGo_Click(object sender, EventArgs e)
        {
            Account act = AccountDBManager.GetAccountByStaffId(cbxID.Text);

            lblFirstname.Text = act.firstName;
            lblLastname.Text = act.lastName;
            lblPosition.Text = act.staffPosition;
        }

        private void btnDelete_Click(object sender, EventArgs e)
        {
            DialogResult result;
            result = MessageBox.Show("Confirm Delete Staff?", "Staff", MessageBoxButtons.YesNo, MessageBoxIcon.Asterisk);

            if (result == DialogResult.Yes)
            {
                AccountDBManager.DeleteAccount(cbxID.Text);
                MessageBox.Show("Account" + cbxID.Text + "Deleted Successful !");
            }
        }

        Home homeChild;
        private void btnCancel_Click(object sender, EventArgs e)
        {
            CloseAllForms();
            if (updateAcctChild == null)
            {
                homeChild = new Home();
                homeChild.Location = new Point(0, 0);
                // Set the Parent Form of the Child window.
                homeChild.MdiParent = this.MdiParent;
                // Display the form.
                homeChild.Show();
                homeChild.Activate();
            }
        }

        #region toolStrip
        UpdateAcct updateAcctChild;
        private void toolStripButton1_Click(object sender, EventArgs e)
        {
            CloseAllForms();
            if (updateAcctChild == null)
            {
                updateAcctChild = new UpdateAcct();
                updateAcctChild.Location = new Point(0, 0);
                // Set the Parent Form of the Child window.
                updateAcctChild.MdiParent = this.MdiParent;
                // Display the form.
                updateAcctChild.Show();
                updateAcctChild.Activate();
            }
        }

        CreateNewAcct createAcctChild;
        private void toolStripButton2_Click(object sender, EventArgs e)
        {
            CloseAllForms();
            if (createAcctChild == null)
            {
                createAcctChild = new CreateNewAcct();
                createAcctChild.Location = new Point(0, 0);
                // Set the Parent Form of the Child window.
                createAcctChild.MdiParent = this.MdiParent;
                // Display the form.
                createAcctChild.Show();
                createAcctChild.Activate();
            }
        }

        DeleteAcct deleteAcct;
        private void toolStripButton3_Click(object sender, EventArgs e)
        {
            CloseAllForms();
            if (deleteAcct == null)
            {
                deleteAcct = new DeleteAcct();
                deleteAcct.Location = new Point(0, 0);
                // Set the Parent Form of the Child window.
                deleteAcct.MdiParent = this.MdiParent;
                // Display the form.
                deleteAcct.Show();
                deleteAcct.Activate();
            }
        }
        #endregion toolStrip

        #region CloseAllForms
        private void CloseAllForms()
        {
            Form[] formToClose = null;
            int i = 1;
            foreach (Form form in Application.OpenForms)
            {
                if (form != this && form.IsMdiChild) //this is form1
                {
                    Array.Resize(ref formToClose, i);
                    formToClose[i - 1] = form;
                    i++;
                }
            }
            if (formToClose != null)
            {
                for (int j = 0; j < formToClose.Length; j++)
                {
                    formToClose[j].Close();
                }
                updateAcctChild = null;
                createAcctChild = null;
                deleteAcct = null;
                homeChild = null;
            }
        }
        #endregion CloseAllForms

        
    }
}
